home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Technical.Notes / PDOS / TN.PDOS.009 < prev    next >
Encoding:
Text File  |  1988-12-15  |  3.5 KB  |  81 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6.  
  7. ProDOS 8
  8. #9:    Buffer Management Using BASIC.SYSTEM
  9.  
  10. Revised by:    Matt Deatherage                                  November 1988
  11. Revised by:    Pete McDonald                                     October 1985
  12.  
  13. This Technical Note discusses methods for allocating buffers which will not be 
  14. arbitrarily deallocated in BASIC.SYSTEM.
  15. _____________________________________________________________________________
  16.  
  17. Section A.2.1 of the ProDOS 8 Technical Reference Manual describes in detail 
  18. how an application may obtain a buffer from BASIC.SYSTEM for its own use.  The 
  19. buffer will be respected by BASIC.SYSTEM, so if you choose to put a program or 
  20. other executable code in there, it will be safe.
  21.  
  22. However, BASIC.SYSTEM does not provide a way to selectively deallocate the 
  23. buffers it has allocated.  Although it is quite easy to allocate space by 
  24. calling GETBUFR ($BEF5) and also quite easy to deallocate by calling FREEBUFR 
  25. ($BEF8), it is not so easy to use FREEBUFR to deallocate a particular buffer.
  26.  
  27. In fact, FREEBUFR always deallocates all buffers allocated by GETBUFR.  This 
  28. is fine for transient applications, but a method is needed to protect a static 
  29. code buffer from being deallocated by FREEBUFR for a static application.
  30.  
  31. Location RSHIMEM ($BEFB) contains the high byte of the highest available 
  32. memory location for buffers, normally $96.  FREEBUFR uses it to determine the 
  33. beginning page of the highest (or first) buffer.  By lowering the value of 
  34. RSHIMEM immediately after the first call to GETBUFR, and before any call to 
  35. FREEBUFR, we can fool FREEBUFR into not reclaiming all the space.  So although 
  36. it is not possible to selectively deallocate buffers, it is still possible to 
  37. reserve space that FREEBUFR will not reclaim.
  38.  
  39. Physically, we place the code buffer between BASIC.SYSTEM and its buffers, in 
  40. the space from $99FF down.
  41.  
  42. After creating the protected static code buffer, we can call GETBUFR and 
  43. FREEBUFR to maintain temporary buffers as needed by our protected module.  
  44. FREEBUFR will not reclaim the protected buffer until after RSHIMEM is restored 
  45. to its original value.
  46.  
  47. The following is a skeleton example which allocates a two-page buffer for a 
  48. static code module, protects it from FREEBUFR, then deprotects it and restores 
  49. it to its original state.
  50.  
  51. START    LDA #$02            ;get 2 pages
  52.          JSR GETBUFR 
  53.          LDA RSHIMEM         ;get current RSHIMEM
  54.          SEC                 ;ready for sub
  55.          SBC #$02            ;minus 2 pages
  56.          STA RSHIMEM         ;save new val to fool FREEBUFR
  57.          JSR FREEBUFR        ;CALL FREEBUFR to deallocate.
  58.  
  59. At this point, the value of RSHIMEM is the page number of the beginning of our 
  60. protected buffer.  The static code may now use GETBUFR and FREEBUFR for 
  61. transient file buffers without fear of freeing its own space from RSHIMEM to 
  62. $99FF.
  63.  
  64. To release the protected space, simply restore RSHIMEM to its original value 
  65. and perform a JSR FREEBUFR.
  66.  
  67. END      LDA RSHIMEM         ;get current val
  68.          CLC                 ;ready for ADD
  69.          ADC #2              ;give back 2 pages
  70.          STA RSHIMEM         ;tell FREEBUFR about it
  71.          JSR FREEBUFR        ;DO FREEBUFR
  72.          RTS 
  73.  
  74. You can reserve any number of pages using this method, as long as the amount 
  75. you reserve is within available memory limits. 
  76.  
  77.  
  78. Further Reference
  79. o    ProDOS 8 Technical Reference Manual
  80.  
  81.